<?php
namespace Admin\Controller;
use Common\Controller\CommonController;
class StatisticsController extends CommonController {
    public function index(){
    	$model = M("booking");
		if(isset($_GET["date"])) {
			if($_GET["date"] == "format") {
				$where = "DATE_FORMAT(timestamp,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m')";
			}else {
				$where = "";
			}
		}else {
			$where = "";
		}
    	$data = $model->field("booking.*,user_id,SUM(breakfast),SUM(lunch), user.name, user.tobelongto")->join("LEFT JOIN user ON booking.user_id = user.id")->where($where)->group("booking.user_id")->order("id")->select();
		$this->assign("total",count($data));
		$this->assign("data",$data);
        $this->display();
    }
}